#include <stdio.h>
#include <stdlib.h>

#include <sys/socket.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <time.h>

#include <unistd.h>

#include "proto.h"

#define IPSTRSIZE 40

static void server_job(int sd);

int main()
{
    int sd = socket(AF_INET, SOCK_STREAM, 0 /*IPPROTO_TCP, IPPROTO_SCTP*/);
    if (sd < 0)
    {
        perror("socket()");
        exit(1);
    }

    struct sockaddr_in raddr;
    raddr.sin_family = AF_INET;
    raddr.sin_port = htons(SERVERPORT);
    inet_pton(AF_INET, "0.0.0.0", &raddr.sin_addr);

    if (connect(sd, (struct sockaddr *)&raddr, sizeof(raddr)) < 0)
    {
        perror("Connection()");
        exit(1);
    }

    server_job(sd);
    close(sd);

    exit(0);
}

static void server_job(int sd)
{
    char buf[BUFSIZ];

    if (recv(sd, buf, BUFSIZ, 0) < 0)
    {
        perror("send()");
        exit(1);
    }
    
    printf("%s\n", buf);
}